﻿using System;
using System.Data;
using DevExpress.XtraEditors;
using UniMana.Utils.Data;
using UniMana.Data;
using UniMana.Utils.Helper;

namespace UniMana.Win.Training
{
    public partial class FrmStudent_SubScoresByTerm : DevExpress.XtraEditors.XtraForm
    {
        public string m_strStudentID = "";
        public int m_iTrainingProgramKey=-1;
        private DBMain m_Catalogue = new DBMain();
        private bool m_bCheckAll = false;
        private RprScoreOfStudentByTermSchoolYearCredits.PersonelSignature m_eSignature;
        public FrmStudent_SubScoresByTerm(string studentID,int trainingProgramKey=-1)
        {
            InitializeComponent();
            //XtraMessageBox.Show("Chức năng đang sửa chữa!","Thông báo");
            //this.Close();
            SysUtils.SetRuleControl(this.Controls, this.Name);
            lueCatalogue_Term1.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
            lueCatalogue_Term2.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
            m_strStudentID = studentID;
            m_iTrainingProgramKey = trainingProgramKey;
            ckeAll.Checked = true;
            radioSignature.SelectedIndex = 0;
        }
        public FrmStudent_SubScoresByTerm(string studentID)
        {
            InitializeComponent();
            m_strStudentID = studentID;
            SysUtils.SetRuleControl(this.Controls, this.Name);
            lueCatalogue_Term1.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
            lueCatalogue_Term2.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
            ckeAll.Checked = true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            #region [oldCode]
            //if (!ckeAll.Checked)
            //{
            //    if (lueCatalogue_Term1.EditValue != null && lueCatalogue_Term2.EditValue != null)
            //    {
            //        FrmView_Student_Scores_ByTerm f = new FrmView_Student_Scores_ByTerm(false, lueCatalogue_Term1.GetIntValue(),
            //                                                                lueCatalogue_Term2.GetIntValue(), m_iTrainingProgramKey);
            //        f.StudentScoresInfo(m_strStudentID);
            //        this.Close();
            //    }
            //    else
            //    {
            //        XtraMessageBox.Show("Vui lòng chọn học kì!", "Thông báo");
            //    }
            //}
            //else
            //{
            //    FrmView_Student_Scores_ByTerm f = new FrmView_Student_Scores_ByTerm(true, lueCatalogue_Term1.GetIntValue(),
            //                                                       lueCatalogue_Term2.GetIntValue(), m_iTrainingProgramKey);
            //    f.StudentScoresInfo(m_strStudentID);
            //    //this.Close();
            //}
            #endregion
            if (!ckeAll.Checked)
            {
                if (lueCatalogue_Term1.EditValue != null && lueCatalogue_Term2.EditValue != null)
                {
                    if (lueCatalogue_Term1.GetIntValue().ToInt() <= lueCatalogue_Term2.GetIntValue().ToInt())
                    {
                        RprScoreOfStudentByTermSchoolYearCredits rpt = new RprScoreOfStudentByTermSchoolYearCredits(m_strStudentID,m_eSignature, m_bCheckAll,
                                                                            lueCatalogue_Term1.GetIntValue(), lueCatalogue_Term2.GetIntValue(), m_iTrainingProgramKey);
                        rpt.ShowPreview();
                    }
                    else
                    {
                        XtraMessageBox.Show("Sinh viên không có điểm!","Thông báo");
                    }
                }
                else
                {
                    XtraMessageBox.Show("Vui lòng chọn học kì!", "Thông báo");
                }
            }
            else
            {
                DataTable _dtInfoStudent = new DataTable();
                Training_ScoreInfo infoScore = new Training_ScoreInfo();
                _dtInfoStudent = infoScore.GetInfoStudentByID(m_strStudentID).ToDataTable();
                if (_dtInfoStudent.Rows.Count > 0)
                {
                    RprScoreOfStudentByTermSchoolYearCredits rpt = new RprScoreOfStudentByTermSchoolYearCredits(m_strStudentID,m_eSignature, m_bCheckAll, -1, -1, m_iTrainingProgramKey);
                    rpt.ShowPreview();
                }
                else
                {
                    XtraMessageBox.Show("Mã sinh viên không tồn tại","Thông báo");
                }
            }
        }
        private void ckeAll_CheckedChanged(object sender, EventArgs e)
        {
            if (ckeAll.Checked)
            {
                lueCatalogue_Term1.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
                lueCatalogue_Term2.GetData(m_Catalogue.m_DCReadOnly.Catalogue_Terms, "Catalogue_TermKey", "Name");
                lueCatalogue_Term1.Enabled = false;
                lueCatalogue_Term2.Enabled = false;
                m_bCheckAll = true;
            }
            else
            {
                lueCatalogue_Term1.Enabled = true;
                lueCatalogue_Term2.Enabled = true;
                m_bCheckAll = false;
            }
        }
        private void radioSignature_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (radioSignature.SelectedIndex == 0)
            {
                m_eSignature = RprScoreOfStudentByTermSchoolYearCredits.PersonelSignature.HieuTruong;
            }
            else if (radioSignature.SelectedIndex == 1)
            {
                m_eSignature = RprScoreOfStudentByTermSchoolYearCredits.PersonelSignature.TruongPhongDaoTao;
            }
            else
            {
                m_eSignature = RprScoreOfStudentByTermSchoolYearCredits.PersonelSignature.HieuTruong;
            }
        }
    }
}